package com.whq.thrift.api.web.admin.service.verify.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.methodinfo.MethodInfo;
import com.whq.thrift.api.web.admin.db.methodinfo.MethodInfoMapper;
import com.whq.thrift.api.web.admin.service.verify.MethodInfoService;

@Service
public class MethodInfoServiceImpl implements MethodInfoService {
	@Autowired
	private MethodInfoMapper methodInfoMapper;

	public void addMethod(MethodInfo method) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (method == null) {
			return;
		}

		Date now = new Date();
		method.setUpdateTime(now);
		Date now1 = new Date();
		method.setCreateTime(now1);

		this.methodInfoMapper.addMethod(method);
	}

	public void updateMethod(MethodInfo method) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (method == null) {
			return;
		}

		Date now = new Date();
		method.setUpdateTime(now);

		this.methodInfoMapper.updMethod(method);
	}

	public void deleteMethod(int id) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");

		this.methodInfoMapper.delMethod(id);
	}

	public int findMethodsCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");

		return this.methodInfoMapper.findMethodsCount(whereParams);
	}

	public MethodInfo getMethodByName(String name) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");

		return this.methodInfoMapper.getMethodByName(name);
	}

	public MethodInfo getMethodById(int id) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");

		return this.methodInfoMapper.getMethodById(id);
	}

	public List<MethodInfo> findMethodsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		return this.methodInfoMapper.findMethodsByIdMap(whereParams);
	}

//	public MethodInfo getMethodByIdentity(String identity) {
//		DataSourceContextHolder.set("dataSourceSyzsVerify");
//
//		return this.methodInfoMapper.getMethodByIdentity(identity);
//	}

//	public int getMethodCountByIdentity(String identity, int id) {
//		DataSourceContextHolder.set("dataSourceSyzsVerify");
//
//		return this.methodInfoMapper.getMethodCountByIdentity(identity, id);
//	}

	public List<MethodInfo> getAllMethodInfo() {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.methodInfoMapper.findAllMethodInfo();
	}

	public List<MethodInfo> findApiInfoList(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.methodInfoMapper.findApiInfoList(whereParams);
	}

}